package com.deer.wms.ware.task.web;

import com.deer.wms.ware.task.model.SO.SoDetailFile;
import com.deer.wms.ware.task.model.SO.SoDetailFileCriteria;
import com.deer.wms.ware.task.service.SoDetailFileService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.deer.wms.project.root.core.result.Result;
import com.deer.wms.project.root.core.result.ResultGenerator;

import java.util.List;

/**
* Created by ll on 2020/02/03.
*/
@Api(description = "SO详细信息归档api接口")
@RestController
@RequestMapping("/so/detail/files")
public class SoDetailFileController {

    @Autowired
    private SoDetailFileService soDetailFileService;

    @PostMapping("/insert")
    public Result add(@RequestBody SoDetailFile soDetailFile) {
        soDetailFileService.save(soDetailFile);
        return ResultGenerator.genSuccessResult();
    }

    @GetMapping("/delete")
    public Result delete(Integer id) {
        soDetailFileService.removeById(id);
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/update")
    public Result update(@RequestBody SoDetailFile soDetailFile) {
        soDetailFileService.updateById(soDetailFile);
        return ResultGenerator.genSuccessResult();
    }

    @GetMapping("/detail")
    public Result detail(Integer id) {
        SoDetailFile soDetailFile = soDetailFileService.getById(id);
        return ResultGenerator.genSuccessResult(soDetailFile);
    }

    @GetMapping("/list")
    public Result list(SoDetailFileCriteria criteria) {
        PageHelper.startPage(criteria.getPageNum(), criteria.getPageSize());
        List<SoDetailFile> list = soDetailFileService.findList(criteria);
        PageInfo pageInfo = new PageInfo(list);
        return ResultGenerator.genSuccessResult(pageInfo);
    }

}
